<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0" />
    <title>写文章</title>
    <link rel="icon" th:href="${config.SITE_ICON}">
    <link rel="stylesheet" th:href="${config.SITE_CDN+'/static/css/bootstrap.min.css'}"/>
    <link rel="stylesheet" th:href="${config.SITE_CDN+'/static/iconfont/iconfont.css'}"/>
    <link rel="stylesheet" th:href="${config.SITE_CDN+'/static/css/app.css'}"/>
</head>
<body>
    <div class="z-content">
        <div class="z-card">
            <div class="z-card-body">
                <div class="z-tabs z-tabs-easy">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#basicConfig" data-toggle="tab" aria-expanded="true">基础设置</a></li>
                        <li><a href="#storageConfig" data-toggle="tab" aria-expanded="false">存储设置</a></li>
                        <li><a href="#emailConfig" data-toggle="tab" aria-expanded="false">邮件设置</a></li>
                        <li><a href="#otherConfig" data-toggle="tab" aria-expanded="false">其他设置</a></li>
                    </ul>
                    <div class="tab-content">
                        <div id="basicConfig" class="tab-pane active">
                            <form id="siteForm" class="form-horizontal">
                                <div class="z-card-body box-body">
                                    <div class="form-group">
                                        <label class="col-lg-2 col-sm-3 control-label">网站域名  <span class="text-danger">*</span>:</label>
                                        <div class="col-md-5 col-sm-8">
                                            <input th:value="${config.SITE_HOST}" type="text" class="form-control" name="SITE_HOST" placeholder="网站域名http(s)" require="">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 col-sm-3 control-label">网站名称 <span class="text-danger">*</span>:</label>
                                        <div class="col-md-5 col-sm-8">
                                            <input th:value="${config.SITE_NAME}" type="text" class="form-control" name="SITE_NAME" placeholder="网站名称/标题" require="">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 col-sm-3 control-label">网站图标 <span class="text-danger">*</span>:</label>
                                        <div class="col-md-5 col-sm-8">
                                            <div class="input-group">
                                                <input th:value="${config.SITE_ICON}" type="text" name="SITE_ICON" class="form-control" placeholder="网站图标url" require="">
                                                <span class="input-group-btn">
                                                      <button type="button" class="btn btn-success btn-flat uploader">上传</button>
                                                </span>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 col-sm-3 control-label">网站Logo <span class="text-danger">*</span>:</label>
                                        <div class="col-md-5 col-sm-8">
                                            <div class="input-group">
                                                <input th:value="${config.SITE_LOGO}" type="text" name="SITE_LOGO" class="form-control" placeholder="网站Logo url" require="">
                                                <span class="input-group-btn">
                                                      <button type="button" class="btn btn-success btn-flat uploader">上传</button>
                                                </span>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-lg-7 col-sm-11 ">
                                            <hr class="z-dashed"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 col-sm-3 control-label">网站关键字 <span class="text-danger">*</span>:</label>
                                        <div class="col-md-5 col-sm-8">
                                            <textarea th:text="${config.SITE_KWD}" rows="2" type="text" class="form-control" name="SITE_KWD" placeholder="[SEO] 网站 keywords" require="">
                                            </textarea>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 col-sm-3 control-label">网站描述 <span class="text-danger">*</span>:</label>
                                        <div class="col-md-5 col-sm-8">
                                            <textarea th:text="${config.SITE_DESC}" rows="2" type="text" class="form-control" name="SITE_DESC" placeholder="[SEO] 网站 description" require="">
                                            </textarea>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-lg-7 col-sm-11 ">
                                            <hr class="z-dashed"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 col-sm-3 control-label">CDN域名 : <span class="z-tooltip">
                                                <i class="z-tooltip-i fa fa-info-circle"></i>
                                                <span class="z-tooltip-text z-tooltip-right" style="width:268px; top:-16px;">设置cdn后，前台和后台都将使用cdn下的静态资源，请根据文档设置</span>
                                            </span>
                                        </label>
                                        <div class="col-md-5 col-sm-8">
                                            <input th:value="${config.SITE_CDN}" type="text" class="form-control" name="SITE_CDN" placeholder="网站CDN域名，请确保正确配置">
                                        </div>
                                    </div>
                                    <button type="button" id="saveBasic" class="btn btn-primary">保存</button>
                                </div>
                            </form>
                        </div>
                        <div id="storageConfig" class="tab-pane">
                            <form id="storageForm" class="form-horizontal">
                                <div class="z-card-body box-body">
                                    <div class="form-group">
                                        <label class="col-lg-2 col-sm-3 control-label">存储类型:</label>
                                        <div class="col-md-5 col-sm-8">
                                            <div class="z-radio">
                                                <input type="radio" th:field="*{storageConfig.type}" name="type" value="0" require=""/>
                                                <label><i></i>本地</label>
                                            </div>
                                            <div class="z-radio">
                                                <input type="radio" th:field="*{storageConfig.type}" name="type" value="1" require=""/>
                                                <label><i></i>七牛云</label>
                                            </div>
                                            <div class="z-radio">
                                                <input type="radio" th:field="*{storageConfig.type}" name="type" value="2" require=""/>
                                                <label><i></i>阿里云</label>
                                            </div>
                                            <div class="z-radio">
                                                <input type="radio" th:field="*{storageConfig.type}" name="type" value="3" require=""/>
                                                <label><i></i>腾讯云</label>
                                            </div>
                                        </div>
                                    </div>
                                    <div id="local-form" th:class="${storageConfig.type==0?'':'display-none'}">
                                        <div class="form-group">
                                            <div class="col-lg-2 col-sm-3  control-label">文件服务器域名: *</div>
                                            <div class="col-md-5 col-sm-8">
                                                <input type="text" class="form-control" th:value="${storageConfig.localDomain}" name="localDomain" placeholder="本地文件服务器域名"/>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-lg-2 col-sm-3  control-label">本地文件存储路径:</div>
                                            <div class="col-md-5 col-sm-8  control-label">
                                                文件将保存在用户目录workDir的file下, <span class="text-danger">[[${workDir}]]file</span>
                                            </div>
                                        </div>
                                    </div>
                                    <div id="qiniu-form" th:class="${storageConfig.type==1?'':'display-none'}">
                                        <div class="form-group">
                                            <label class="col-lg-2 col-sm-3  control-label">域名 : </label>
                                            <div class="col-md-5 col-sm-8">
                                                <input type="text" class="form-control" th:value="${storageConfig.qiniuDomain}" name="qiniuDomain" require="必填项"  placeholder="七牛云绑定的域名">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-lg-2 col-sm-3  control-label">路径前缀 :</label>
                                            <div class="col-md-5 col-sm-8">
                                                <input type="text" class="form-control" th:value="${storageConfig.qiniuPrefix}" name="qiniuPrefix" require="必填项"  placeholder="不设置默认为空">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-lg-2 col-sm-3  control-label">AccessKey :</label>
                                            <div class="col-md-5 col-sm-8">
                                                <input type="text" class="form-control" th:value="${storageConfig.qiniuAccessKey}" name="qiniuAccessKey" require="必填项"  placeholder="七牛云AccessKey">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-lg-2 col-sm-3  control-label">SecretKey :</label>
                                            <div class="col-md-5 col-sm-8">
                                                <input type="text" class="form-control" th:value="${storageConfig.qiniuSecretKey}" name="qiniuSecretKey" require="必填项"  placeholder="七牛云SecretKey">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-lg-2 col-sm-3  control-label">BucketName :</label>
                                            <div class="col-md-5 col-sm-8">
                                                <input type="text" class="form-control" th:value="${storageConfig.qiniuBucketName}" name="qiniuBucketName" require="必填项"  placeholder="七牛云BucketName">
                                            </div>
                                        </div>
                                    </div>
                                    <div id="ali-form" th:class="${storageConfig.type==2?'':'display-none'}">
                                        <div class="form-group">
                                            <div class="col-lg-2 col-sm-3  control-label">域名</div>
                                            <div class="col-md-5 col-sm-8">
                                                <input type="text" class="form-control" th:value="${storageConfig.aliyunDomain}" name="aliyunDomain" placeholder="阿里云绑定的域名"/>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-lg-2 col-sm-3  control-label">路径前缀</div>
                                            <div class="col-md-5 col-sm-8">
                                                <input type="text" class="form-control" th:value="${storageConfig.aliyunPrefix}" name="aliyunPrefix" placeholder="不设置默认为空"/>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-lg-2 col-sm-3  control-label">EndPoint</div>
                                            <div class="col-md-5 col-sm-8">
                                                <input type="text" class="form-control" th:value="${storageConfig.aliyunEndPoint}" name="aliyunEndPoint" placeholder="阿里云EndPoint"/>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-lg-2 col-sm-3  control-label">AccessKeyId</div>
                                            <div class="col-md-5 col-sm-8">
                                                <input type="text" class="form-control" th:value="${storageConfig.aliyunAccessKeyId}" name="aliyunAccessKeyId" placeholder="阿里云AccessKeyId"/>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-lg-2 col-sm-3  control-label">AccessKeySecret</div>
                                            <div class="col-md-5 col-sm-8">
                                                <input type="text" class="form-control" th:value="${storageConfig.aliyunAccessKeySecret}" name="aliyunAccessKeySecret" placeholder="阿里云AccessKeySecret"/>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-lg-2 col-sm-3  control-label">BucketName</div>
                                            <div class="col-md-5 col-sm-8">
                                                <input type="text" class="form-control" th:value="${storageConfig.aliyunBucketName}" name="aliyunBucketName" placeholder="阿里云BucketName"/>
                                            </div>
                                        </div>
                                    </div>
                                    <div id="qcloud-form" th:class="${storageConfig.type==3?'':'display-none'}">
                                        <div class="form-group">
                                            <div class="col-lg-2 col-sm-3  control-label">域名</div>
                                            <div class="col-md-5 col-sm-8">
                                                <input type="text" class="form-control" th:value="${storageConfig.qcloudDomain}" name="qcloudDomain" placeholder="腾讯云绑定的域名"/>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-lg-2 col-sm-3  control-label">路径前缀</div>
                                            <div class="col-md-5 col-sm-8">
                                                <input type="text" class="form-control" th:value="${storageConfig.qcloudPrefix}" name="qcloudPrefix" placeholder="不设置默认为空"/>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-lg-2 col-sm-3  control-label">SecretId</div>
                                            <div class="col-md-5 col-sm-8">
                                                <input type="text" class="form-control" th:value="${storageConfig.qcloudSecretId}" name="qcloudSecretId" placeholder="腾讯云SecretId"/>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-lg-2 col-sm-3  control-label">SecretKey</div>
                                            <div class="col-md-5 col-sm-8">
                                                <input type="text" class="form-control" th:value="${storageConfig.qcloudSecretKey}" name="qcloudSecretKey" placeholder="腾讯云SecretKey"/>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-lg-2 col-sm-3  control-label">BucketName</div>
                                            <div class="col-md-5 col-sm-8">
                                                <input type="text" class="form-control" th:value="${storageConfig.qcloudBucketName}" name="qcloudBucketName" placeholder="腾讯云BucketName"/>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-lg-2 col-sm-3  control-label">Bucket所属地区</div>
                                            <div class="col-md-5 col-sm-8">
                                                <input type="text" class="form-control" th:value="${storageConfig.qcloudRegion}" name="qcloudRegion" placeholder="如：sh（可选值 ，华南：gz 华北：tj 华东：sh）"/>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-8">
                                            <button id="saveStorage" type="button" class="btn btn-primary">启用</button>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div id="emailConfig" class="tab-pane">
                            <form id="emailForm" class="form-horizontal">
                                <div class="z-card-body box-body">
                                    <div class="form-group">
                                        <label class="col-lg-2 col-sm-3 control-label">服务器 <span class="text-danger">*</span>: <span class="z-tooltip">
                                                    <i class="z-tooltip-i fa fa-info-circle"></i>
                                                    <span class="z-tooltip-text z-tooltip-right">只支持配置SMTP服务</span>
                                                </span>
                                        </label>
                                        <div class="col-md-5 col-sm-8">
                                            <input th:value="${emailConfig.host}" type="text" class="form-control" name="host" placeholder="邮件服务器host" require="">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 col-sm-3 control-label">端口  <span class="text-danger">*</span>:</label>
                                        <div class="col-md-5 col-sm-8">
                                            <input th:value="${emailConfig.port}" type="text" class="form-control" name="port" placeholder="邮件服务器端口" require="">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 col-sm-3 control-label">用户名  <span class="text-danger">*</span>:</label>
                                        <div class="col-md-5 col-sm-8">
                                            <input th:value="${emailConfig.username}" type="text" class="form-control" name="username" placeholder="用户名" require="">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 col-sm-3 control-label">密码  <span class="text-danger">*</span>:</label>
                                        <div class="col-md-5 col-sm-8">
                                            <input th:value="${emailConfig.password}" type="text" class="form-control" name="password" placeholder="授权码" require="">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 col-sm-3 control-label">发件人  <span class="text-danger">*</span>:</label>
                                        <div class="col-md-5 col-sm-8">
                                            <input th:value="${emailConfig.from}" type="text" class="form-control" name="from" placeholder="发件人" require="">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-8">
                                            <button id="saveEmail" type="button" class="btn btn-primary">保存</button>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div id="otherConfig" class="tab-pane">
                            <form id="otherForm" class="form-horizontal">
                                <div class="z-card-body box-body">
                                    <div class="form-group">
                                        <label class="col-lg-2 col-sm-3 control-label">编辑器类型 <span class="text-danger">*</span>: <span class="z-tooltip">
                                                    <i class="z-tooltip-i fa fa-info-circle"></i>
                                                    <span class="z-tooltip-text z-tooltip-right" style="width:180px;">切换后对新建文章生效</span>
                                                </span>
                                        </label>
                                        <div class="col-md-5 col-sm-8">
                                            <select name="EDITOR_TYPE"  class="form-control">
                                                <option value="1" th:selected="${config.EDITOR_TYPE=='1'}">wangEditor</option>
                                                <option value="2" th:selected="${config.EDITOR_TYPE=='2'}">markdown</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 col-sm-3 control-label">重置密码方式 <span class="text-danger">*</span>: <span class="z-tooltip">
                                                <i class="z-tooltip-i fa fa-info-circle"></i>
                                                <span class="z-tooltip-text z-tooltip-right" style="top: -15px">如设置邮件,请确保您的账号信息已完善邮箱</span>
                                            </span>
                                        </label>
                                        <div class="col-md-5 col-sm-8">
                                            <select name="RESET_PWD_TYPE"  class="form-control">
                                                <option value="1" th:selected="${config.RESET_PWD_TYPE=='1'}">安全码</option>
                                                <option value="2" th:selected="${config.RESET_PWD_TYPE=='2'}">邮件</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 col-sm-3 control-label">安全码  <span class="text-danger">*</span>:</label>
                                        <div class="col-md-5 col-sm-8">
                                            <input th:value="${config.SECURITY_CODE}" type="text" class="form-control" name="SECURITY_CODE" placeholder="安全码" require="">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 col-sm-3 control-label">网站创建时间  <span class="text-danger">*</span>:</label>
                                        <div class="col-md-5 col-sm-8">
                                            <input id="systemCreateTime" th:value="${config.SYSTEM_CREATE_TIME}" type="text" class="form-control" name="SYSTEM_CREATE_TIME" placeholder="网站创建时间" require="">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-8">
                                            <button id="saveOther" type="button" class="btn btn-primary">保存</button>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div id="send-email-modal" class="display-none">
        <form class="form-horizontal" id="sendEmailForm">
            <div class="z-card-body">
                <div class="form-group">
                    <label  class="col-sm-3 control-label">接收邮箱 <span class="text-danger">*</span>:</label>
                    <div class="col-sm-8">
                        <input type="text" name="to" class="form-control" require="" email="" placeholder="接收测试邮件的邮箱地址"/>
                    </div>
                </div>
                <div class="form-group">
                    <label  class="col-sm-3 control-label">邮件标题 <span class="text-danger">*</span>:</label>
                    <div class="col-sm-8">
                        <input type="text" name="subject" class="form-control" require="" placeholder="测试邮件标题"/>
                    </div>
                </div>
                <div class="form-group">
                    <label  class="col-sm-3 control-label">邮件内容 :</label>
                    <div class="col-sm-8">
                        <textarea type="text" rows="3" class="form-control" name="content" require="" placeholder="测试邮件内容"></textarea>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <script th:src="${config.SITE_CDN+'/static/js/jquery.min.js'}"></script>
    <script th:src="${config.SITE_CDN+'/static/js/bootstrap.min.js'}"></script>
    <script th:src="${config.SITE_CDN+'/static/laydate/laydate.js'}"></script>
    <script th:src="${config.SITE_CDN+'/static/js/app.js'}"></script>
    <script type="text/javascript">
        $(function () {
            App.initSelect("select");
            App.initUploader({
                pick: '.uploader',
                url:'/upload/upload',
                accept:'jpg,png',
                before:function(){
                    App.mask(".uploader");
                },
                onSuccess:function(picker,res){
                    App.unmask(".uploader");
                    if(res.status===200){
                        $(picker).parent().prev().val(res.data.fileFullPath);
                    }
                }
            });
            laydate.render({
                elem: '#systemCreateTime'
            });
            $("#saveBasic").on('click',function () {
                if(App.validate("#siteForm")){
                    App.mask("#saveBasic");
                    App.postAjax("/admin/config/save",$("#siteForm").serialize(),function (data) {
                        App.unmask("#saveBasic");
                        if(data.status===200){
                            App.msgS(data.msg);
                        }else{
                            App.msgE(data.msg);
                        }
                    })
                }
            });
            $("#saveStorage").on('click', function () {
                App.unmask("#saveStorage");
                App.postAjax("/admin/config/save/storage",$("#storageForm").serialize(),function (data) {
                    App.unmask("#saveStorage");
                    if(data.status===200){
                        App.msgS(data.msg);
                    }else{
                        App.msgE(data.msg);
                    }
                })
            });
            $("#saveEmail").on('click', function () {
                if(App.validate("#emailForm")) {
                    App.unmask("#saveEmail");
                    App.postAjax("/admin/config/save/email", $("#emailForm").serialize(), function (data) {
                        App.unmask("#saveEmail");
                        if (data.status === 200) {
                            App.confirm({content:"保存成功，是否进行邮件测试？"},function () {
                                var emailPopId = App.popup({
                                    title: "邮件测试",
                                    btn:["发送"],
                                    content: $("#send-email-modal"),
                                    onCancel: App.resetForm("#sendEmailForm")
                                },function () {
                                    if(App.validate("#sendEmailForm")){
                                        App.postAjax("/admin/email/send",$("#sendEmailForm").serialize(),function (data) {
                                            if(data.status===200){
                                                App.msgS(data.msg);
                                                App.closePopup(emailPopId);
                                                App.resetForm("#sendEmailForm");
                                            }else{
                                                App.msgE(data.msg);
                                            }
                                        })
                                    }
                                })
                            });
                        } else {
                            App.msgE(data.msg);
                        }
                    })
                }
            });
            $("#saveOther").on('click',function () {
                if(App.validate("#otherForm")){
                    App.mask("#saveOther");
                    App.postAjax("/admin/config/save",$("#otherForm").serialize(),function (data) {
                        App.unmask("#saveOther");
                        if(data.status===200){
                            App.msgS(data.msg);
                        }else{
                            App.msgE(data.msg);
                        }
                    })
                }
            });
            $("input[name=type]").on('change', function() {
                var ossType = $(this).val();
                if(ossType==="0"){
                    $("#local-form").show();
                    $("#qiniu-form").hide();
                    $("#ali-form").hide();
                    $("#qcloud-form").hide();
                }else if(ossType==="1"){
                    $("#local-form").hide();
                    $("#qiniu-form").show();
                    $("#ali-form").hide();
                    $("#qcloud-form").hide();
                }else if(ossType==="2"){
                    $("#local-form").hide();
                    $("#qiniu-form").hide();
                    $("#ali-form").show();
                    $("#qcloud-form").hide();
                }else if(ossType==="3"){
                    $("#local-form").hide();
                    $("#qiniu-form").hide();
                    $("#ali-form").hide();
                    $("#qcloud-form").show();
                }
            });
        });
    </script>
</body>
</html>